<template>
	<div style="height: 500px; ">
		<!--src="https://pan.baidu.com/"-->
		<iframe src="https://openapi.baidu.com/oauth/2.0/authorize?response_type=code&client_id=FskBOhTPxIGRRQB7IRPcSDkQ&redirect_uri=oob&scope=basic,netdisk&display=popup&qrcode=1"
		 id="iframe" scrolling="no" frameborder="0" style="width: 100%;  height: 100vh;"></iframe>
	</div>
</template>

<script>
	import axios from "axios";
	export default {
		mounted() {
			var _this = this;
			const iframe = document.getElementById("iframe");
			// 处理兼容行问题
			if (iframe.attachEvent) {
				iframe.attachEvent("onload", function() {
					// iframe加载完毕以后执行操作
					alert("ifrnme没有加载完成");
				});
			} else {
				iframe.onload = function() {
					// iframe加载完毕以后执行操作
					console.log("iframe已加载完毕111111");
					if (
						iframe.contentWindow.document.getElementById("Verifier").value != null
					) {
						var code = iframe.contentWindow.document.getElementById("Verifier")
							.value;
						console.log(code);
						axios.get(
								"https://openapi.baidu.com/oauth/2.0/token?grant_type=authorization_code&code=" +
								code +
								"&client_id=FskBOhTPxIGRRQB7IRPcSDkQ&client_secret=TVVhWo9SnfMvkB8CBX4aQ0yGxpsTjwCG&redirect_uri=oob", {}
							)
							.then(function(respanse) {
								// _this.arr1 = respanse.data.access_token
								window.sessionStorage.setItem(
									"access_token",
									respanse.data.access_token
								);
								_this.$router.push("/Baidu_Home");
							});
					}
					// _this.$router.push('/Baidu/code')
				};
			}
		},
		created() {
			this.getUserList();
		},
		methods: {
			getUserList() {}
		}
	};
</script>

<style>
</style>
